#ifndef SERVERGAMEMANAGER_H
#define SERVERGAMEMANAGER_H

#include "GameManager.h"
#include <QRect>

class ServerGameManager : public GameManager
{
public:
    ServerGameManager();

    virtual void GameLoop();

    virtual bool IsServer() const { return true; }

    void AddPlayer(const Player &player);
    void RemovePlayer(int id);

public slots:
    // Client -> Server (Instance is server)
    virtual void SlotProcessRequest(CommandPtr request);

    // Server -> Client (Instance is client)
    virtual void SlotPlayerList(PlayerlistBean* playerlist_bean){}
    virtual void SlotMap(MapBean* map_bean){}
    virtual void SlotSnapshot(SnapshotBean* snapshot_bean){}

private:
    QMap< int, QList<Command::CommandType> > m_commandQueue;
    QMap< int, qreal>  m_tankLastFired;

    template <typename T>
    void fillDistances(QList<T>& objects, QList< QPair<T, unsigned> >& distances, double elapsed);

    template <typename T>
    void fillRotatingObjects(QList<T>& objects, QList<T>& output);

    bool movesIntoObstacle(DynamicObject* object);
    bool objectsCollide(DynamicObject* first, DynamicObject* second);

    void ProcessCommand(TankPtr tank);
    void AddCommand(int id, Command::CommandType command);
};

#endif // SERVERGAMEMANAGER_H
